package com.RequestYunZhuWang;

/**
 * 人员实名制接口对外web  中建三局广州三馆合一，若要新对接数据请复制本类，改动下方的请求参数appKey、appid那些东西
 * 或者在调用方法里面进行set到本类变量，下方详细setProjectKey  setProjectCode   //目前采用该方法
 * @author XiaoHuang
 */
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MainRealNameSystemInterface {

	   static String url="http://lwapi.yzw.cn/open.api";                  //该处即使是不同的项目也不变，云筑网唯一请求数据路径
       static String appid="ysznkj";                                      //应用程序id   申请下来的appid见当初申请下发密钥的邮箱
       static String projectCode="321837";                                //projectcode登录云筑网平台查看是、https://lw.yzw.cn/Project
       
       static String appKey=   "4743f46c6c9e49c3b9de8064372a3447";      //中建三局统一是该key,该key是申请提交后云筑网发送到接收邮箱的秘钥
       static String projectKey="86c6ef8ef5514a0eae7b1556765f87b3";     //根据登录云筑网账号查看项目编号（projectCode）对应的数据验证密钥
       
       static String appSecret=appKey+projectKey;                       //appsecret  见文档http://lwapi.yzw.cn/
       
       static String version="1.0";                                       //通用版本1.0  通常不会变
	
       
     //对接除了三馆外其他需要数据的第三方提供的便利方法
      	public static void setProjectKey(String projectKey) {
      		MainRealNameSystemInterface.projectKey = projectKey;
      		appSecret=appKey+projectKey; 
      	}
      	
      	public static void setProjectCode(String projectCode) {
      		MainRealNameSystemInterface.projectCode = projectCode;
      	}
	
	
	/**
	 * 获取所有的地区数据列表
	 * @param jsonObject
	 * @return
	 */
	public String GetAreaList(JSONObject jsonObject) {
		    String method="Common.GetAreaList";         //请求方法  见文档http://lwapi.yzw.cn/
		    
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);

	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
	           
	            
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 获取所有的配置数据列表(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetCommonConfigList(JSONObject jsonObject) {
	        String method="Common.GetCommonConfigList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        
	        String data = JSON.toJSONString(rawData);
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);

	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 获取所有的通用字典数据列表(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetCommonDictList(JSONObject jsonObject) {
	        String method="Common.GetCommonDictList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	
	/**
	 * 获取所有的通用字典类型列表
	 * @param jsonObject
	 * @return
	 */
	public String GetCommonDictTypeList(JSONObject jsonObject) {
	        String method="Common.GetCommonDictTypeList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 获取所有的工种字典数据列表(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetWorkTypeDictList(JSONObject jsonObject) {
	        String method="Common.GetWorkTypeDictList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	
	/**
	 * 分页模式通过项目编号、上一次获取时间，获取这段时间内更新了的所有工人实名信息
	 * @param jsonObject
	 * @return
	 */
	public String GetWorkerInfoList(JSONObject jsonObject) {
	        String method="Common.GetWorkerInfoList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("SortFields", jsonObject.get("SortFields"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);

	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 通过ProjectCode获取本项目信息
	 * @param jsonObject
	 * @return
	 */
	public String GetProjectMaster(JSONObject jsonObject) {
	        String method="Project.GetProjectMaster";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("FilterByDate", jsonObject.get("FilterByDate"));
	        
	        log.info("projectKey:"+projectKey);
	        log.info("appSecret:"+appSecret);
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}

	/**
	 * 通过ProjectCode获取本项目分包商信息
	 * @param jsonObject
	 * @return
	 */
	public String GetSubcontractorList(JSONObject jsonObject) {
	        String method="Project.GetSubcontractorList";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 通过ProjectCode获取本项目班组基础信息(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetTeamMaster(JSONObject jsonObject) {
	        String method="Project.GetTeamMaster";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 通过ProjectCode获取本项目班组成员信息(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetTeamMember(JSONObject jsonObject) {
	        String method="Project.GetTeamMember";
	        
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("EndTime", jsonObject.get("EndTime"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("TeamDataIds", jsonObject.get("TeamDataIds"));
	        
	        String data = JSON.toJSONString(rawData);

	        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

	        String sortString = "appid=" + appid;
	        String guid = UUID.randomUUID().toString().replace("-","");
	        String timeStamp = sdf.format(new Date());

	        sortString += "&data=" + data;
	        sortString += "&format=json";
	        sortString += "&method=" + method;
	        sortString += "&nonce=" + guid;
	        sortString += "&timeStamp=" + timeStamp;
	        sortString += "&version=" + version;
	        sortString += "&appsecret=" + appSecret;

	        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());
	        log.info(String.format("加密后签名串为：%s",sign));

	        BaseRequest request = new BaseRequest(){};
	        Map<String,String> dataMap = new HashMap<>();
	        String res="返回layui需要的格式到layui（该默认值表示报错情况）";
	        
	        dataMap.put("appid",appid);
	        dataMap.put("projectCode",projectCode);
	        dataMap.put("data", data);


	        dataMap.put("format","json");
	        dataMap.put("method",method);
	        dataMap.put("nonce",guid);
	        dataMap.put("timeStamp",timeStamp);
	        dataMap.put("version",version);
	        dataMap.put("sign",sign);
	        try {
	            res = request.postData(url,null,dataMap);
//	            dataMap.put("appSecret",appSecret);
	            log.info(String.format("调用结果：%s",res));
	            return res;
	        } catch (Exception ex) {
	            String errorMsg = "";
	            if (ex.getMessage().contains("ClientProtocolException")) {
	                errorMsg = "异常：输入的URL无效";
	                return errorMsg;
	            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
	                errorMsg = "异常：输入的URL不正确";
	                return errorMsg;
	            }
	            log.info(errorMsg);
	            return res;
	        }

	}
	
	/**
	 * 通过ProjectCode获取本项目班组成员信息(带时间戳)
	 * @param jsonObject
	 * @return
	 */
	public String GetTeamMember_O(JSONObject jsonObject) {
	        String method="Project.GetTeamMember_O";
	        Map rawData = new HashMap();
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	/**
	 * 获取总包方通用配置信息√  这里开始下面先做完本类所有
	 * @param jsonObject
	 * @return
	 */
	public String GetContractorProjectConfig(JSONObject jsonObject) {
	        String method="Project.GetContractorProjectConfig";
	        Map rawData = new HashMap();
	        rawData.put("ContractorCode", jsonObject.get("ContractorCode"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取项目工人考勤记录（最新版本）  √
	 * @param jsonObject
	 * @return
	 */
	public String GetProjectAttendanceListNew(JSONObject jsonObject) {
	        String method="Project.GetProjectAttendanceListNew";
	        Map rawData = new HashMap();
	        rawData.put("ProjectSysNo", jsonObject.get("ProjectSysNo"));
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("WorkerSysNo", jsonObject.get("WorkerSysNo"));
	        rawData.put("WorkerSysNoList", jsonObject.get("WorkerSysNoList"));
	        rawData.put("SubContractorSysNo", jsonObject.get("SubContractorSysNo"));
	        rawData.put("TeamSysNo", jsonObject.get("TeamSysNo"));
	        rawData.put("WorkerName", jsonObject.get("WorkerName"));
	        rawData.put("BeginDate", jsonObject.get("BeginDate"));
	        rawData.put("EndDate", jsonObject.get("EndDate"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        rawData.put("SortFields", jsonObject.get("SortFields"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取项目工人列表
	 * @param jsonObject
	 * @return
	 */
	public String GetWorkerList(JSONObject jsonObject) {
	        String method="Project.GetWorkerList";
	        Map rawData = new HashMap();
	        rawData.put("ProjectSysNo", jsonObject.get("ProjectSysNo"));
	        rawData.put("IDCardNumber", jsonObject.get("IDCardNumber"));
	        rawData.put("WorkerName", jsonObject.get("WorkerName"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);
	        log.info("dataMap:"+dataMap);
	        log.info("method:"+method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取项目工人考勤数据列表（最新版本）
	 * @param jsonObject
	 * @return
	 */
	public String GetWorkerAttendanceListNew(JSONObject jsonObject) {
	        String method="Project.GetWorkerAttendanceListNew";
	        Map rawData = new HashMap();
	        rawData.put("ProjectSysNo", jsonObject.get("ProjectSysNo"));
	        rawData.put("WorkerSysNo", jsonObject.get("WorkerSysNo"));
	        rawData.put("TeamSysNo", jsonObject.get("TeamSysNo"));
	        rawData.put("BeginDate", jsonObject.get("BeginDate"));
	        rawData.put("EndDate", jsonObject.get("EndDate"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取工人职业履历
	 * @param jsonObject
	 * @return
	 */
	public String GetWorkerProjectHistoryList(JSONObject jsonObject) {
	        String method="Project.GetWorkerProjectHistoryList";
	        Map rawData = new HashMap();
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("IDCardNumber", jsonObject.get("IDCardNumber"));
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取身份证阅读器配置
	 * @param jsonObject
	 * @return
	 */
	public String GetIDCardReaderConfig(JSONObject jsonObject) {
	        String method="Project.GetIDCardReaderConfig";
	        Map rawData = new HashMap();
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        rawData.put("ClientId", jsonObject.get("ClientId"));
	        rawData.put("ProjectSysNo", jsonObject.get("ProjectSysNo"));
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("BeginTime", jsonObject.get("BeginTime"));
	        rawData.put("PageIndex", jsonObject.get("PageIndex"));
	        rawData.put("PageSize", jsonObject.get("PageSize"));
	        rawData.put("SortFields", jsonObject.get("SortFields"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 项目层首页统计
	 * @param jsonObject
	 * @return
	 */
	public String QueryProjectRealTimeInfo(JSONObject jsonObject) {
	        String method="Project.QueryProjectRealTimeInfo";
	        Map rawData = new HashMap();
	        rawData.put("ProjectCode", jsonObject.get("ProjectCode"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	
	/**
	 * 获取总包信息
	 * @param jsonObject
	 * @return
	 */
	public String GetContractorInfo(JSONObject jsonObject) {
	        String method="Project.GetContractorInfo";
	        Map rawData = new HashMap();
	        rawData.put("pageIndex", jsonObject.get("pageIndex"));
	        rawData.put("pageSize", jsonObject.get("pageSize"));
	        rawData.put("socialNumber", jsonObject.get("socialNumber"));
	        rawData.put("contractorName", jsonObject.get("contractorName"));
	        rawData.put("TimeStamp", jsonObject.get("TimeStamp"));
	        rawData.put("SK", jsonObject.get("SK"));
	        String data = JSON.toJSONString(rawData);
	        Map<String,String> dataMap = returnDataMap(data,method);

	        return CommonRequest(url,dataMap);

	}
	/**
	 * 返回中部分请求体封装
	 * @param data
	 * @param method
	 * @return
	 */
	private static Map<String,String> returnDataMap(String data,String method) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

        String sortString = "appid=" + appid;
        String guid = UUID.randomUUID().toString().replace("-","");
        String timeStamp = sdf.format(new Date());

        sortString += "&data=" + data;
        sortString += "&format=json";
        sortString += "&method=" + method;
        sortString += "&nonce=" + guid;
        sortString += "&timeStamp=" + timeStamp;
        sortString += "&version=" + version;
        sortString += "&appsecret=" + appSecret;

        String sign = EncriptionHelper.getSignatureWithMD5(sortString.toLowerCase());

        Map<String,String> dataMap = new HashMap<>();
        
        dataMap.put("appid",appid);
        dataMap.put("projectCode",projectCode);
        dataMap.put("data", data);

        dataMap.put("format","json");
        dataMap.put("method",method);
        dataMap.put("nonce",guid);
        dataMap.put("timeStamp",timeStamp);
        dataMap.put("version",version);
        dataMap.put("sign",sign);
		return dataMap;
		
	}
	/**
	 * 返回后部分的通用请求封装
	 * @param url
	 * @param dataMap
	 * @return
	 */
	private static String CommonRequest(String url,Map<String,String> dataMap) {
		String res="返回layui需要的格式到layui（该默认值表示报错情况）";
		BaseRequest request = new BaseRequest(){};
	
		try {
            res = request.postData(url,null,dataMap);
//            dataMap.put("appSecret",appSecret);
            RecordErrorRequest(res);  //记录异常
            log.info(String.format("调用结果：%s",res));
            return res;
        } catch (Exception ex) {
            String errorMsg = "";
            if (ex.getMessage().contains("ClientProtocolException")) {
                errorMsg = "异常：输入的URL无效";
                return errorMsg;
            } else if (ex.getMessage().contains("UnknownHostException") || ex.getMessage().contains("unreachable")) {
                errorMsg = "异常：输入的URL不正确";
                return errorMsg;
            }
            log.info(errorMsg);
            return res;
		
	}
}
	
	private static void RecordErrorRequest(String res) {
		String responCode = "";
		 try {
			 responCode = JSONObject.parseObject(res).getString("code");
			} catch (Exception e) {
				log.debug("获取请求体code未完成...--异常是："+e);
			}
		 if(Integer.parseInt(responCode) != 0 ) {
			 
			 log.debug(JSONObject.parseObject(res).getString("message")+",将要保存该此失败请求的参数..");
			 log.debug("保存完成！");
		 }
			 
		 
	}
}